﻿using System;

using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;

namespace AMC.SubstitutionCache.Drivers
{
    public abstract class DisplayTemplateSubstitutionDriver<TPart> : SubstitutionDriver<TPart>
        where TPart : ContentPart, new()
    {
        protected DisplayTemplateSubstitutionDriver()
        {
            AddHandledShape(() => CreateHandledShape(DisplayTemplateShapeType, GroupId, false, DisplayTemplateShapeLocator));
        }

        protected abstract string TemplateName { get; }

        protected virtual string DisplayTemplateShapeType { get { return GetDisplayTemplateShapeType(TemplateName); } }

        protected override Action<BuildShapeContext, dynamic> ShapeConfig
        {
            get
            {
                return (context, shape) =>
                {
                    shape.DisplayTemplateShapeType = DisplayTemplateShapeType;
                };
            }
        }

        protected override ContentShapeResult PlaceholderShape(TPart part, dynamic shapeHelper, string shapeType, string displayType)
        {
            return PlaceholderShape(part, shapeHelper, shapeType, "DisplayTemplate", TemplateName, displayType);
        }
    }
}